class AdminController < ApplicationController
  
  def index
    show
    render :action => 'show'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :show }

  def show
    @setting = Setting.find(:first, :order => "id DESC")
  end

  def create
    @setting = Setting.new(params[:setting])
    if @setting.save
      flash[:notice] = "Die Einstellungen wurden gespeichert."
      redirect_to :action => 'show'
    else
      render :action => 'new'
    end
  end

  def edit 
    @setting = Setting.find(:first, :order => "id DESC")
  end

  def update
    @setting = Setting.find(params[:id])
    @setting.day_starts = params[:day_starts][:hour] + ":" + params[:day_starts][:minute]
    @setting.day_ends = params[:day_ends][:hour] + ":" + params[:day_ends][:minute]
    @setting.break_starts = params[:break_starts][:hour] + ":" + params[:break_starts][:minute]
    @setting.break_ends = params[:break_ends][:hour] + ":" + params[:break_ends][:minute]
    @setting.date_length = params[:setting][:date_length]
    if @setting.save
      flash[:notice] = "Die Einstellungen wurden bearbeitet."
      redirect_to :action => 'show', :id => @setting
    else
      render :action => 'edit'
    end
  end

  def destroy
    Setting.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end
